import json

import requests

url = "https://music.163.com/weapi/cloudsearch/get/web?csrf_token="

heards = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36"
    ,"Referer": "https://music.163.com/search/"
}
e = '010001'
f = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'
g = '0CoJUm6Qyw8W8jud'
i = "3BxQUTwA6bSSPHIZ"
data = {
    "csrf_token": "",
    "hlposttag": "</span>",
    "hlpretag": r"<span class=\"s-fc7\">",
    "limit": "30",
    "offset": "0",
    "s": "晚风",
    "total": "true",
    "type": "1",
}
from Cryptodome.Cipher import AES
from base64 import b64encode
def getEncSecText():
    return "9478f00bc18982b7cd7c6c68b7ae68c4349c74488ed114b1f33947d4cc664ecb533f68695010d1706c68b21e244c0ec096ac238ee9f505e982e8b6a84f32b9fb4d4f8ab517e166658458fea128f26b140a0504d48bbb84b9c491251f5637071537e0a2f91164b09bc0fac9a9e1631405eba2b2167e1ba857cbaba34795e629a8"

def getParams(data):
    first = encParams(data, g)
    second = encParams(first, i)
    return second

def to_16(data):
    pad = 16 - len(data) % 16
    data += chr(pad)*pad
    return data

def encParams(data, key):
    data = to_16(data)
    aes = AES.new(key=key.encode('utf-8'), IV="0102030405060708".encode('utf-8'), mode=AES.MODE_CBC)
    bs = aes.encrypt(data.encode('utf-8'))
    return str(b64encode(bs), 'utf-8')

resp = requests.post(url=url, headers=heards, data={
    "params":getParams(json.dumps(data)),
    "encSecKey": getEncSecText()
})

music_list = resp.json()['result']['songs']

for i in music_list:
    print(i)